﻿/********************************************************************************/
/* 	screen.d																	*/
/*------------------------------------------------------------------------------*/
/*	製作		（　゜ワ゜）ノ　／　松久貫太									*/
/*	製作開始　	2007/05/11														*/
/*	MAIL		omega@personal.email.ne.jp										*/
/*	URL		http://nagoya.cool.ne.jp/o_mega										*/
/*																				*/
/*	このソースは「やらわかライセンス」の元で配布されています。					*/
/*-更新履歴---------------------------------------------------------------------*/
/*	2007/--/--																	*/
/*-その他-----------------------------------------------------------------------*/
/*	なし																		*/
/********************************************************************************/

/* ライブラリのインポート *******************************************************/
private import hell2;
private import opengl;
private import vector;


/* 変換行列の操作 ***************************************************************/

void glTranslatef(float x,float y,float z)
{
	opengl.glTranslatef(x,y,z);
}

void glRotatef(float x,float y,float z)
{
	opengl.glRotatef(x,1,0,0);
	opengl.glRotatef(y,0,1,0);
	opengl.glRotatef(z,0,0,1);
}
void glRotatef(float angle,float x,float y,float z)
{
	opengl.glRotatef(angle,x,y,z);
}

void glLoadIdentity()
{
	opengl.glLoadIdentity();
}

void glPushMatrix()
{
	opengl.glPushMatrix();
}

void glPopMatrix()
{
	opengl.glPopMatrix();
}

void glColor4f(float r,float g,float b,float a)
{
	opengl.glColor4f(r,g,b,a);
}

void glScalef(float x,float y,float z)
{
	opengl.glScalef(x,y,z);
}


/* Shape ************************************************************************/
class Shape{
public:
	static void draw()
	{
		drawWire();
		drawPolygon();
	}
	
	static void drawWire()
	{
	}
	
	static void drawPolygon()
	{
	}
}


/* CubeShape ******************************************************************/

class CubeShape : Shape
{
public:
	static void drawWire()
	{
		glLineWidth(2);
		glBegin(GL_LINE_LOOP);
		glVertex3f(-1.0f	,-1.0f	,-1.0f	);
		glVertex3f(1.0f		,-1.0f	,-1.0f	);
		glVertex3f(1.0f		,1.0f	,-1.0f	);
		glVertex3f(-1.0f	,1.0f	,-1.0f	);
		glEnd();
		glBegin(GL_LINE_LOOP);
		glVertex3f(-1.0f	,-1.0f	,1.0f	);
		glVertex3f(1.0f		,-1.0f	,1.0f	);
		glVertex3f(1.0f		,1.0f	,1.0f	);
		glVertex3f(-1.0f	,1.0f	,1.0f	);
		glEnd();
		glBegin(GL_LINES);
		glVertex3f(-1.0f	,-1.0f	,-1.0f	);
		glVertex3f(-1.0f	,-1.0f	,1.0f	);
		glVertex3f(1.0f		,-1.0f	,-1.0f	);
		glVertex3f(1.0f		,-1.0f	,1.0f	);
		glVertex3f(1.0f		,1.0f	,-1.0f	);
		glVertex3f(1.0f		,1.0f	,1.0f	);
		glVertex3f(-1.0f	,1.0f	,-1.0f	);
		glVertex3f(-1.0f	,1.0f	,1.0f	);
		glEnd();
	}
	
	static void drawPolygon()
	{	// CULL_CCW
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f(1.0f		,1.0f	,-1.0f	);
		glVertex3f(1.0f		,-1.0f	,-1.0f	);
		glVertex3f(-1.0f	,-1.0f	,-1.0f	);
		glVertex3f(-1.0f	,1.0f	,-1.0f	);
		glEnd();
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f(1.0f		,1.0f	,1.0f	);
		glVertex3f(-1.0f	,1.0f	,1.0f	);
		glVertex3f(-1.0f	,-1.0f	,1.0f	);
		glVertex3f(1.0f		,-1.0f	,1.0f	);
		glEnd();
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f(-1.0f	,1.0f	,1.0f	);
		glVertex3f(-1.0f	,1.0f	,-1.0f	);
		glVertex3f(-1.0f	,-1.0f	,-1.0f	);
		glVertex3f(-1.0f	,-1.0f	,1.0f	);
		glEnd();
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f(1.0f		,1.0f	,1.0f	);
		glVertex3f(1.0f		,-1.0f	,1.0f	);
		glVertex3f(1.0f		,-1.0f	,-1.0f	);
		glVertex3f(1.0f		,1.0f	,-1.0f	);
		glEnd();
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f(1.0f		,-1.0f	,1.0f	);
		glVertex3f(-1.0f 	,-1.0f	,1.0f	);
		glVertex3f(-1.0f	,-1.0f	,-1.0f	);
		glVertex3f(1.0f		,-1.0f	,-1.0f	);
		glEnd();
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f(1.0f		,1.0f	,1.0f	);
		glVertex3f(1.0f		,1.0f	,-1.0f	);
		glVertex3f(-1.0f	,1.0f	,-1.0f	);
		glVertex3f(-1.0f 	,1.0f	,1.0f	);
		glEnd();
	}
}


/* ParticleShape ***************************************************************/

class TriangleShape : Shape
{
public:
	static void drawWire()
	{
		glLineWidth(1);
		glBegin(GL_LINE_LOOP);
		glVertex3f(-1		,0			,0	);
		glVertex3f(0.5		,-0.86603	,0	);
		glVertex3f(0.5		,0.86603	,0	);
		glEnd();
	}
	
	static void drawPolygon()
	{	// CULL CCW
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f(-1		,0			,0	);
		glVertex3f(0.5		,-0.86603	,0	);
		glVertex3f(0.5		,0.86603	,0	);
		glEnd();
	}
}

/* LineShape ***************************************************************/
class LineShape : Shape
{
public:
	static void drawWire(Vec3 v1,Vec3 v2)
	{
		glLineWidth(2);
		glBegin(GL_LINES);
		glVertex3f(v1.x		,v1.y		,v1.z	);
		glVertex3f(v2.x		,v2.y		,v2.z	);
		glEnd();
	}
	
	static void drawWireFade(Vec3 v1,Vec3 v2)
	{
		glLineWidth(2);
		glBegin(GL_LINES);
		glVertex3f(v1.x		,v1.y		,v1.z	);
		glColor3f(0,0,0);
		glVertex3f(v2.x		,v2.y		,v2.z	);
		glEnd();
	}
	
	static void drawWireLinesBegin()
	{
		glLineWidth(2);
		glBegin(GL_LINES);
	}
	static void drawWireLinesEnd()
	{
		glEnd();
	}
	static void drawWireLines(Vec3 v1,Vec3 v2)
	{
		glVertex3f(v1.x		,v1.y		,v1.z	);
//		glColor3f(0,0,0);
		glVertex3f(v2.x		,v2.y		,v2.z	);
	}
}

/* HexShape ***************************************************************/
class HexShape : Shape
{
public:
	static void drawWire()
	{
		glLineWidth(2);
		glBegin(GL_LINE_LOOP);
		glVertex3f( 0.5		,0.8661916	,-1	);
		glVertex3f( 1.0		,0.0		,-1	);
		glVertex3f( 0.5		,-0.8661916	,-1	);
		glVertex3f(-0.5		,-0.8661916	,-1	);
		glVertex3f(-1.0		,0.0		,-1	);
		glVertex3f(-0.5		,0.8661916	,-1	);
		glEnd();
		glBegin(GL_LINE_LOOP);
		glVertex3f( 0.5		,0.8661916	,1	);
		glVertex3f( 1.0		,0.0		,1	);
		glVertex3f( 0.5		,-0.8661916	,1	);
		glVertex3f(-0.5		,-0.8661916	,1	);
		glVertex3f(-1.0		,0.0		,1	);
		glVertex3f(-0.5		,0.8661916	,1	);
		glEnd();
		
		glBegin(GL_LINES);
		glVertex3f( 0.5		,0.8661916	,-1	);
		glVertex3f( 0.5		,0.8661916	,1	);
		glVertex3f( 1.0		,0.0		,-1	);
		glVertex3f( 1.0		,0.0		,1	);
		glVertex3f( 0.5		,-0.8661916	,-1	);
		glVertex3f( 0.5		,-0.8661916	,1	);
		glVertex3f(-0.5		,-0.8661916	,-1	);
		glVertex3f(-0.5		,-0.8661916	,1	);
		glVertex3f(-1.0		,0.0		,-1	);
		glVertex3f(-1.0		,0.0		,1	);
		glVertex3f(-0.5		,0.8661916	,-1	);
		glVertex3f(-0.5		,0.8661916	,1	);
		glEnd();
	}
}


/* DeltaShape ***************************************************************/
class DeltaShape : Shape
{
public:
	static void drawWire()
	{
		glLineWidth(2);
		glBegin(GL_LINE_LOOP);
		glVertex3f( 1.0		, 0.0		, 0.0	);
		glVertex3f(-1.0		,-2.0		, 0.0	);
		glVertex3f(-0.5		,-0.0		,-0.0	);
		glVertex3f(-1.0		, 2.0		,-0.0	);
		glEnd();
	}
}

/* NeedleShape ***************************************************************/
class NeedleShape : Shape
{
public:
	static void drawWire()
	{
		glLineWidth(2);
		glBegin(GL_LINE_LOOP);
		glVertex3f(-1.0		, 0.3		, 0.3	);
		glVertex3f(-1.0		,-0.3		, 0.3	);
		glVertex3f(-1.0		,-0.3		,-0.3	);
		glVertex3f(-1.0		, 0.3		,-0.3	);
		glEnd();
		glBegin(GL_LINES);
		glVertex3f(-1.0		, 0.3		, 0.3	);
		glVertex3f( 1.0		, 0 		, 0		);
		glVertex3f(-1.0		,-0.3		, 0.3	);
		glVertex3f( 1.0		, 0			, 0		);
		glVertex3f(-1.0		,-0.3		,-0.3	);
		glVertex3f( 1.0		, 0			, 0		);
		glVertex3f(-1.0		, 0.3		,-0.3	);
		glVertex3f( 1.0		, 0			, 0		);
		glEnd();
	}
}

/* SquareShape ***************************************************************/
class SquareShape : Shape
{
public:
	static void drawWire()
	{
		glLineWidth(2);
		glBegin(GL_LINE_LOOP);
		glVertex3f( 0.5		, 0.5		, 0.0	);
		glVertex3f( 0.5		,-0.5		, 0.0	);
		glVertex3f(-0.5		,-0.5		,-0.0	);
		glVertex3f(-0.5		, 0.5		,-0.0	);
		glEnd();
	}
	static void drawPolygon()
	{	// CULL CCW
		glBegin(GL_TRIANGLE_FAN);
		glVertex3f( 0.5		, 0.5		, 0.0	);
		glVertex3f(-0.5		, 0.5		,-0.0	);
		glVertex3f(-0.5		,-0.5		,-0.0	);
		glVertex3f( 0.5		,-0.5		, 0.0	);
		glEnd();
	}
}

/* OctaTubeShape ************************************************************/

class OctaTubeShape : Shape
{
public:
	static void drawWire()
	{
		glLineWidth(2);
		glBegin(GL_LINE_LOOP);
		glVertex3f( 0.5		, 0.5		, 0.0	);
		glVertex3f( 0.5		,-0.5		, 0.0	);
		glVertex3f(-0.5		,-0.5		,-0.0	);
		glVertex3f(-0.5		, 0.5		,-0.0	);
		glEnd();
	}
}